<?php
require_once("Xiachufang/entity/Remark.php");
class RemarkLogic {
	/**
	 * 获取某个菜谱下的最新评论
	 *
	 * @param unknown_type $recipeId
	 * @param unknown_type $num
	 * @return unknown
	 */
	static function getRecipeRemarks($recipeId, $num=50) {
		$table = RemarkEntity::getTable();
		$sql = "select * from ".$table." where recipe_id=".$recipeId." and food_id=0 order by remark_id desc limit ".$num;
		$db = DbMgr::getSlaver($table);
		return $db->query($sql)->asArray();
	}
	
	/**
	 * 获取某个食物下的所有评论
	 *
	 * @param unknown_type $foodId
	 * @param unknown_type $num
	 * @return unknown
	 */
	static function getFoodRemarks($foodId, $num=50) {
		$table = RemarkEntity::getTable();
		$sql = "select * from ".$table." where food_id=".$foodId." order by remark_id desc limit ".$num;
		$db = DbMgr::getSlaver($table);
		return $db->query($sql)->asArray();
	}
	
	/**
	 * 删除菜谱的所有评论
	 *
	 * @param unknown_type $recipeId
	 * @return unknown
	 */
	static function deleteRecipeRemarks($recipeId) {
		$table = RemarkEntity::getTable();
		$sql = "delete from ".$table." where recipe_id=".$recipeId." and food_id=0";
		$db = DBMgr::getMaster($table);
		return $db->execute($sql)->success;
	}
	
	/**
	 * 删除食物的所有评论
	 *
	 * @param unknown_type $foodId
	 * @return unknown
	 */
	static function deleteFoodRemarks($foodId) {
		$table = RemarkEntity::getTable();
		$sql = "delete from ".$table." where food_id=".$foodId;
		$db = DBMgr::getMaster($table);
		return $db->execute($sql)->success;
	}
}
?>